package com.epoint.clubmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.epoint.clubmanagement.entity.ClubType;
import com.epoint.clubmanagement.mapper.ClubTypeMapper;
import com.epoint.clubmanagement.service.IClubTypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import java.util.List;

/**
 * Title: ClubTypeServiceImpl
 * Description: 俱乐部类型service实现类
 *
 * @author sqn
 * @version 1.0.0
 * @date 2021/3/17 0017 下午 12:17
 */
@Validated
@Service
public class ClubTypeServiceImpl extends ServiceImpl<ClubTypeMapper, ClubType> implements IClubTypeService {

    @Autowired
    private ClubTypeMapper clubTypeMapper;

    /**
     * 分页查询俱乐部类型数据
     *
     * @param pageNum  第几页
     * @param pageSize 每页多少条数据
     * @param param    查询参数-俱乐部类型名称
     * @return
     */
    @Override
    public IPage<ClubType> selectClubTypePage(int pageNum, int pageSize, String param) {
        QueryWrapper<ClubType> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(param)) {
            queryWrapper.like("type_name", param);
        }
        Page<ClubType> page = new Page<>(pageNum, pageSize);
        return clubTypeMapper.selectPage(page, queryWrapper);
    }

    /**
     * 新增一条俱乐部类型信息
     *
     * @param clubType
     */
    @Override
    public int addClubType(@Valid ClubType clubType) {
        return clubTypeMapper.insert(clubType);
    }

    /**
     * 修改一条俱乐部类型信息
     *
     * @param clubType
     */
    @Override
    public int editClubType(@Valid ClubType clubType) {
        return clubTypeMapper.updateById(clubType);
    }

    /**
     * 根据主键id查询一个俱乐部类型对象
     *
     * @param id
     * @return
     */
    @Override
    public ClubType queryClubTypeById(Integer id) {
        return clubTypeMapper.selectById(id);
    }

    /**
     * 根据主键id删除一个俱乐部类型对象
     *
     * @param id
     * @return
     */
    @Override
    public int delClubTypeById(Integer id) {
        return clubTypeMapper.deleteById(id);
    }

    /**
     * 查询所有俱乐部类型
     *
     * @return
     */
    @Override
    public List<ClubType> queryClubTypeList() {
        return clubTypeMapper.selectList(null);
    }
}
